﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Model.Statistical;
using System.Data;

namespace Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem.OGWell
{
    public partial class CommData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            int page = Request.Params["page"].ToInt32();
            int pagesize = Request.Params["rows"].ToInt32();
            string sort =Request.Params["sort"].ToRequestString();

            string field = HttpContext.Current.Request.QueryString["field"].ToRequestString().Decrypt();
            string orderby = HttpContext.Current.Request.QueryString["orderby"].ToRequestString();
            string tn = HttpContext.Current.Request.QueryString["tn"].ToRequestString();
            string year = HttpContext.Current.Request.QueryString["year"].ToRequestString();
            string month = HttpContext.Current.Request.QueryString["month"].ToRequestString();
            string dwbm = HttpContext.Current.Request.QueryString["dwbm"].ToRequestString();
            GridData data = new GridData(field, tn, dwbm, year, month, orderby);
            if (page == 0 && pagesize == 0)
            {
                string json = data.GetDataSet().Tables[0].ToJsonForGrid();

                Response.Write(json);
                Response.End();
            }
            else
            {
                DataTable dt = data.GetDataSet().Tables[0];
                string json = "";

                if (dt.Rows.Count == 0)
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = DBNull.Value;
                    dt.Rows.Add(dr);                    
                }

                json = dt.ToJsonForGrid(page, pagesize);
                Response.Write(json);
                Response.End();
            }
        }
    }
}